<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />   
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/multiselect.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base-2.3.0.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all-2.3.0.js">
        </script>
		<script type="text/javascript" src="../../scripts/grid/RowExpander-2.3.0.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/EditableItem.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/RangeMenu.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GridFilters.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/Filter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/DateFilter.js"></script>
        <script type="text/javascript" src="../../scripts/form/DDView.js">
        </script>
        <script type="text/javascript" src="../../scripts/form/MultiSelect.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
		<script type="text/javascript" src="../../scripts/imageViewer.js"></script>
        <script type="text/javascript">
        var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
        var uiMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.message');
        var messageName = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=com.hilaver.dzmis');
        var plMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.producttimeline.isfinished');
        var sendForm;
        var acUserStore;
        var acUserGrid;

        var ctYesno = new i18nMessage('../../servlet/CodeTableServlet?name=CtYesno');

        var sysMsgViewerStore;
        var sysMsgViewerGrid;

        var userXMLReader = new Ext.data.XmlReader({
            record: 'item'
        }, [{
            name: 'id',
            mapping: 'id'
        }, {
            name: 'userName',
            mapping: 'userName'
        }, {
            name: 'realName',
            mapping: 'realName'
        }]);
	
		var userXmlLoader = new xmlLoader('../../servlet/AcUserServlet?action=5&sort=id&dir=asc');
		var userRecords = userXMLReader.readRecords(userXmlLoader.getXml()).records;
		var userArray = new Array();
		for(var i = 0; i < userRecords.length; i ++){
			var userRecord = userRecords[i];
			//alert(userRecord.data.id);
			userArray.push([userRecord.data.id, userRecord.data.realName + '(' + userRecord.data.userName + ')']);
		}

        var msgId = getPrarmeterValue(window.location, 'id');
        var startPage = getPrarmeterValue(window.location, 'startPage');
        var isClosed = getPrarmeterValue(window.location, 'isClosed');
        if(isClosed == null && isClosed == ''){
        	isClosed = '02';
        }
        var editCallback = function(){
        	sendForm.getForm().load({
				url:'../../servlet/SysMboxServlet?action=103&id=' + editId, 
				waitMsg:Ext.LoadMask.prototype.msg, 
				success: function(form, action){
					Ext.getCmp('receiverIds').setValue([action.result.data.receiverId]);
					Ext.getCmp('receiverIds').disabled = true;
					sysMsgViewerStore.load();
				},
				failure: function(o){
					messageTip.msg(message.get('message.tip'), message.get('message.load.unsuccessful'));
				}
			});
		}

        var deleteCallback = function(btn){
            if (btn == 'yes') {
                Ext.Ajax.request({
                    url: '../../servlet/SysMboxServlet?action=102&id=' + deleteId,
                    success: function(o){
                        if (o.responseText == 'success') {
                        	sysMsgViewerStore.load();
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.successful'));
                        }
                        else {
                            messageTip.msg(message.get('message.tip'), message.get('message.delete.unsuccessful'));
                        }
                    },
                    failure: function(o){
                        messageTip.msg(message.get('message.tip'), message.get('message.delete.failure'));
                    },
                    params: {
                        foo: 'bar'
                    }
                });
            }
        }
        
        var msgXMLReader = new Ext.data.XmlReader({
            record: 'item'
        }, [{
            name: 'id',
            mapping: 'id'
        }, {
            name: 'ctClassName',
            mapping: 'ctClassName'
        }, {
            name: 'objId',
            mapping: 'objId'
        }, {
            name: 'parentClassName',
            mapping: 'parentClassName'
        }, {
            name: 'parentObjId',
            mapping: 'parentObjId'
        }, {
            name: 'ctOperation',
            mapping: 'ctOperation'
        }, {
            name: 'modifier',
            mapping: 'modifier'
        }, {
            name: 'modifyDate',
            mapping: 'modifyDate'
        }, {
            name: 'isClosed',
            mapping: 'isClosed'
        }, {
            name: 'message',
            mapping: 'message'
        }, {
            name: 'message',
            mapping: 'message'
        }]);
	
		var xmlLoader = new xmlLoader('../../servlet/SysMboxServlet?action=11&id=' + msgId);
		var msgRecord = msgXMLReader.readRecords(xmlLoader.getXml()).records[0];
		var itemTpl = new Ext.XTemplate(
					'<table cellspacing="0" id="the-table" style="width: 100%;"><tbody>',
						'<tr><td style="background:#eeeeee;">',
						plMessage.get('ui.producttimeline.isfinished'),
						'</td><td>{[this.getIsClosed(values.isClosed)]}</td>',
						'<td style="background:#eeeeee;">',
						uiMessage.get('ui.message.operation'),
						'</td><td>{[this.getOperation(values.ctOperation)]}</td>',
						'<td style="background:#eeeeee;">',
						uiMessage.get('ui.message.name'),
						'</td><td>{[this.getMsgName(values.ctClassName)]}</td></tr>',
						'<tr><td style="background:#eeeeee;">',
						message.get('message.edit.date'),
						'</td><td>{modifyDate}</td>',
						'<td style="background:#eeeeee;">',
						uiMessage.get('ui.message.modifier'),
						'</td><td>{modifier}</td>',
						'<td style="background:#eeeeee;">',
						message.get('message.edit.go'),
						'</td><td>{[this.getGo(values.ctClassName, values.ObjId, values.parentObjId)]}</td></tr>',
					'</tbody></table>',{
						getOperation:function(value){
							if(value == '01'){
	                    		return String.format('<img src="../../images/icons/add.png" title="' + message.get('message.action.add') + '" />');
	                    	}else if(value == '02'){
	                    		return String.format('<img src="../../images/icons/pencil.png" title="' + message.get('message.list.eidt') + '" />');	
	                    	}else{
	                    		return String.format('<img src="../../images/icons/delete.png" title="' + message.get('message.list.delete') + '" />');
	                    	}
						},
						getMsgName:function(value){
							return messageName.get(value);
						},
						getGo: function(ctClassName, objId, parentId){
							var urlObj = getUrl(ctClassName);
	        	    		return String.format('<a href="javascript:parent.addTab(\'{0}\', \'' + urlObj.url  + '\', \'{3}\');void(0);"><img src="../../images/icons/arrow_rotate_clockwise.png" title="{4}" /></a>', urlObj.menuId, objId, parentId, messageName.get(ctClassName),message.get('message.edit.go'));
						},
						getIsClosed: function(value){
							if(value == '01'){
	                    		return String.format('<img src="../../images/icons/tick.png" title="' + message.get('message.list.yes') + '" />');
	                    	}else if(value == '02'){
	                    		return String.format('<img src="../../images/icons/cross.png" title="' + message.get('message.list.no') + '" />');	
	                    	}
						}
					}
		);

		Ext.onReady(function(){
			itemTpl.overwrite('mboxDiv', msgRecord.data);
			
            Ext.QuickTips.init();
            Ext.form.Field.prototype.msgTarget = 'side';

            sendForm = new Ext.FormPanel({
		        labelAlign: 'left',
				url: '../../servlet/SysMboxServlet?action=101',
		        frame:true,
		        title: uiMessage.get('ui.message.sendmsg'),
		        bodyStyle:'padding:5px 5px 5px 5px;margin-top: 2px;',
		        width: '100%',
				labelWidth: 75,
				reader: new Ext.data.XmlReader({
			                record: 'item'
			            }, [{
			                name: 'id',
			                mapping: 'id'
			            }, {
			                name: 'q1',
			                mapping: 'q1'
			            }, {
			                name: 'q2',
			                mapping: 'q2'
			            }, {
			                name: 'q3',
			                mapping: 'q3'
			            }, {
			                name: 'a1',
			                mapping: 'a1'
			            }, {
			                name: 'a2',
			                mapping: 'a2'
			            }, {
			                name: 'a3',
			                mapping: 'a3'
			            },{
				            name: 'receiverId',
				            mapping: 'receiverId'
			            }]),
				collapsible: true,
		        items: [{
                        id: 'msgId',
                        name: 'msgId',
                        xtype: 'hidden',
						value: msgRecord.data.id
                	},{
                        id: 'id',
                        name: 'id',
                        xtype: 'hidden'
                	},{
						layout: 'column',
						items: [{
							columnWidth:.20,
			                layout: 'form',
							items: [{
								id: 'receiverIds',
								name: 'receiverIds',
					            xtype:"multiselect",
					            hideLabel: true,
					            dataFields:["id", "realName"], 
					            valueField:"id",
					            displayField:"realName",
					            width:'95%',
					            height:200,
					            allowBlank:false,
					            //disabled: true,
					            //value: 17,
					            blankText: message.get('message.edit.noblank'),
					            data: userArray,
					            tbar:[{
					                //text:message.get('message.edit.reset') + '(' +uiMessage.get('ui.message.pressctrl') + ')',
					                text: uiMessage.get('ui.message.pressctrl'),
					                handler:function(){
						                //Ext.getCmp('receiverIds').reset();
						            }
					            }]
					        }]
						},{
							columnWidth:.40,
			                layout: 'form',
							items: [{
		                        fieldLabel: uiMessage.get('ui.message.q') + '1',
		                        name: 'q1',
		                        xtype: 'textarea',
		                        maxLength: 512,
		                        allowBlank:false,
								width: '90%',
		                        maxLengthText: message.get('message.edit.toolong')
		                    },{
		                        fieldLabel: uiMessage.get('ui.message.q') + '2',
		                        name: 'q2',
		                        xtype: 'textarea',
		                        maxLength: 512,
								width: '90%',
		                        maxLengthText: message.get('message.edit.toolong')
		                    },{
		                        fieldLabel: uiMessage.get('ui.message.q') + '3',
		                        name: 'q3',
		                        xtype: 'textarea',
		                        maxLength: 512,
								width: '90%',
		                        maxLengthText: message.get('message.edit.toolong')
		                    }]
						},{
							columnWidth:.40,
			                layout: 'form',
							items: [{
		                        fieldLabel: uiMessage.get('ui.message.a') + '1',
		                        name: 'a1',
		                        xtype: 'textarea',
		                        maxLength: 512,
								width: '90%',
		                        maxLengthText: message.get('message.edit.toolong')
		                    },{
		                        fieldLabel: uiMessage.get('ui.message.a') + '2',
		                        name: 'a2',
		                        xtype: 'textarea',
		                        maxLength: 512,
								width: '90%',
		                        maxLengthText: message.get('message.edit.toolong')
		                    },{
		                        fieldLabel: uiMessage.get('ui.message.a') + '3',
		                        name: 'a3',
		                        xtype: 'textarea',
		                        maxLength: 512,
								width: '90%',
		                        maxLengthText: message.get('message.edit.toolong')
		                    }]
						}]
		        	}],
		
		        buttons: [{
		            text: message.get('message.edit.save'),
					handler: function(){
                        if (sendForm.getForm().isValid()) {
                            sendForm.getForm().submit({
                                method: 'post',
                                success: function(form, action){
                                    messageTip.msg(message.get('message.tip'), message.get('message.edit.successful'));
                                    sendForm.getForm().reset();
									sysMsgViewerStore.load();
									Ext.getCmp('receiverIds').disabled = false;
                                },
                                failure: function(form, action){
                                    messageTip.msg(message.get('message.tip'), message.get('message.edit.unsuccessful'));
                                }
                            });
                        }
                    }
		        },{
					text: message.get('message.edit.reset'),
					handler: function(){
						sendForm.getForm().reset();
						Ext.getCmp('receiverIds').disabled = false;
					}
				},{
		            text: message.get('message.edit.cancel'),
                    handler: function(){
                        if (startPage != null) {
                            window.location = 'sys_mbox_list.html?isClosed=' + isClosed +'&startPage=' + startPage;
                        }else {
                            window.location = 'sys_mbox_list.html?isClosed=' + isClosed;
                        }
                    }
		        }]
		    });
            sendForm.render('sendDiv');
			//Ext.getCmp('receiverIds').setValue([17,16]);

            sysMsgViewerStore = new Ext.data.Store({
                url: '../../servlet/SysMboxServlet?action=105&id=' + msgRecord.data.id,
                
                reader: new Ext.data.XmlReader({
                    record: 'item',
                    id: 'id',
                    totalRecords: 'itemTotal'
                }, [ 
                'index', 'isFinished', {name: 'sender.realName', mapping: 'senderName'}, {name: 'receiver.realName', mapping: 'receiverName'}, 'createDate', 'modifyDate', 'q1', 'q2', 'q3','a1', 'a2','a3','id']),
                
                remoteSort: false
            }); 

            var expander = new Ext.grid.RowExpander({
		        tpl : new Ext.XTemplate(
		        	'<br/><p><b>' + uiMessage.get('ui.message.q') + '1:&nbsp;&nbsp;</b> {q1}</p>',
		        	'<br/><p><b>' + uiMessage.get('ui.message.a') + '1:&nbsp;&nbsp;</b> {a1}</p>',
		        	'<br/><p><b>' + uiMessage.get('ui.message.q') + '2:&nbsp;&nbsp;</b> {q2}</p>',
		        	'<br/><p><b>' + uiMessage.get('ui.message.a') + '2:&nbsp;&nbsp;</b> {a2}</p>',
		        	'<br/><p><b>' + uiMessage.get('ui.message.q') + '3:&nbsp;&nbsp;</b> {q3}</p>',
		        	'<br/><p><b>' + uiMessage.get('ui.message.a') + '3:&nbsp;&nbsp;</b> {a3}</p>'
		        )
		    });
            var filters = new Ext.grid.GridFilters({
				  filters:[
					{type: 'string',  dataIndex: 'sender.realName'},
					{type: 'string',  dataIndex: 'receiver.realName'},
					{type: 'date',  dataIndex: 'createDate'},
					{type: 'date',  dataIndex: 'modifyDate'},
					{type: 'list',  dataIndex: 'isFinished',options: ctYesno.getCtArray()}
			]});
			
			sysMsgViewerGrid = new Ext.grid.GridPanel({
                title: uiMessage.get('ui.message.sendlist'),
                store: sysMsgViewerStore,
                plugins: [expander,filters],
				stripeRows: true,
                height: 360,
                columns: [expander,{
                    header: message.get('message.list.id'),
                    dataIndex: 'index'
                },{
                    header: uiMessage.get('ui.message.finished'),
                    dataIndex: 'isFinished',
                    sortable: true,
                    renderer: function(value, metaData, record){
	    	    		if(value == '01'){
	        	    		return String.format('<img src="../../images/icons/tick.png" title="' + message.get('message.list.yes') + '" />');
	    	    		}else{
	    	    			return String.format('<img src="../../images/icons/cross.png" title="' + message.get('message.list.no') + '" />');
	        	    	}
	    	        }
                },{
                    header: uiMessage.get('ui.message.sender'),
                    sortable: true,
                    dataIndex: 'sender.realName'
                },{
                    header: uiMessage.get('ui.message.recevier'),
                    sortable: true,
                    dataIndex: 'receiver.realName'
                },{
                    header: uiMessage.get('ui.message.createdate'),
                    sortable: true,
                    dataIndex: 'createDate'
                },{
                    header: uiMessage.get('ui.message.modifydate'),
                    sortable: true,
                    dataIndex: 'modifyDate',
                    renderer: function(value, metaData, record){
	    	    		if(record.data.modifyDate == record.data.createDate){
	        	    		return '';
	    	    		}else{
	    	    			return record.data.modifyDate;
	        	    	}
	    	        }
                },{
                    header: message.get('message.list.eidt'),
                    dataIndex: 'id',
                    renderer: renderEdit
                },{
                    header: message.get('message.list.delete'),
                    dataIndex: 'id',
                    renderer: renderDelete
                }],
                viewConfig: {
                    forceFit: true
                },
                loadMask: true,
                renderTo: 'sendListDiv'
            });
			
			sysMsgViewerStore.load();
			
			function renderEdit(value, p, record){
                return String.format('<a href="javascript: editItem(editCallback, {0});"><img src="../../images/icons/pencil.png" title="' + message.get('message.list.eidt') + '" /></a>', record.id);
            }
            
            function renderDelete(value, p, record){
                return String.format('<a href="javascript: deleteItem(deleteCallback, {0});"><img src="../../images/icons/delete.png" title="' + message.get('message.list.delete') + '"/></a>', record.id);
            }
			
            
		});
		
       
        </script>
	</head>
	<body>
		<div id="mboxDiv">
        </div>
        <div id="sendDiv" style="margin-top: 5px;">
        </div>
        <div id="sendListDiv" style="margin-top: 5px;">
        </div>
	</body>
</html>